﻿
@{
    var Title = ViewBag.Title as Frame.Core.Models.Titles;
}
@section body {
    <form class="layui-form" action="">
        <div class="mainBox" style="background-color:#fff">
            <div class="main-container">
                <input class="layui-hide" name="ID" value="@Title.ID" />
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">职称名称:</label>
                    <div class="layui-input-block">
                        <input type="text" name="Name" lay-verify="required" placeholder="请输入职称" autocomplete="off" class="layui-input" value="@Title.Name" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">职称备注:</label>
                    <div class="layui-input-block">
                        <textarea name="Remark" placeholder="请输入内容" class="layui-textarea" style="height:200px;">@Title.Remark</textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="button-container">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit="" lay-filter="user-save">
                    <i class="layui-icon layui-icon-ok"></i>
                    提交
                </button>
                <button type="reset" class="pear-btn pear-btn-md">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
}
@section script {

    <script>
        layui.use(['form', 'view'], function () {
            let form = layui.form;
            let view = layui.view;



            //监听提交
            form.on('submit(user-save)', function (data) {
                //layer.alert(JSON.stringify(data.field), {
                //    title: '最终的提交信息'
                //})
                //请求登入接口
                view.req({
                    url: 'TitleEdit_Update' //实际使用请改成服务端真实接口
                    , data: { ajaxJson: JSON.stringify(TrimObjToNewObj(data.field)), __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value }
                    , type: "post"
                    , dataType: "json"
                    //, contentType: 'application/json'
                    , done: function (res) {
                        if (res.codeIndex == 1) {
                            layer.msg(res.msg, {
                                offset: '15px'
                                , icon: 1
                                , time: 1000
                            });

                            //加载top窗体专用，通过Iframe中id查找对应的窗体
                            //top.document.getElementById('5').contentWindow.btnSearchClick();
                        } else {
                            layer.msg(res.msg, {
                                offset: 't',
                                anim: 6
                            });
                        }

                    }
                });

                return false;
            });
        })
        //遍历对象去值的空格
        function TrimObjToNewObj(obj) {
            for (var index in obj) {
                obj[index] = trim(obj[index]);
            }
            return obj;
        }
        function trim(str) { //删除左右两端的空格
            return str.replace(/(^\s*)|(\s*$)/g, "");
        }
    </script>
}


